$(function(){
    let id=location.search.split('?')[1]
    if(id){
        getBolgById(id).then(res=>{
            $('[name=id]').val(res['data'].id)
            $('[name=title]').val(res['data'].title)
            $('[name=tips]').val(res['data'].tips)
            $('[name=content]').val(res['data'].content)
            $('[name=type]').val(res['data'].type)
            $('[name=author]').val(res['data'].author)
            $('[name=time]').val(res['data'].time)
            $('[name=supplier]').val(res['data'].supplier)
        })
    }
 })


 
function save() {
    let id=$('[name=id]').val();
    let title=$('[name=title]').val();
    let tips=$('[name=tips]').val();
    let content=$('[name=content]').val();
    let type=$('[name=type]').val();
    let author=$('[name=author]').val();
    let time=$('[name=time]').val();
    let supplier=$('[name=supplier]').val();
    let obj={
        id,title,tips,content,type,author,time,supplier
    }


    if(obj.id){
        putBolg(obj.id,obj).then(data=>{
            
            if(data.code===1000){
                location.href='./index.html'
            }else{
                alert(code.msg)
            }
        })
    }else{
        postBolg(obj).then(data=>{

            if(data.code===1000){
                location.href='./index.html'
            }else{
                alert(code.msg)
            }
        })
    }
    
}


function cancel(){

    window.location.href='./index.html'
}